#ifndef _CRENDERING_H
#define _CRENDERING_H

#include "sdl2/SDL.h"
#include <Windows.h>

typedef enum RenderDisMode {
  DisMode_FullScreen,
  DisMode_FitWindow_Stretch,
  DisMode_FitWindow_KeepRatio,
  DisMode_Free
} RenderDisMode_e;

typedef enum RenderFormat {
  RenderFormat_YUV420P,
  RenderFormat_RGB,
} RenderFormat_e;

typedef struct RenderRect {
  int x;
  int y;
  int width;
  int height;
} RenderRect_t;

class CVRender {
public:
  CVRender();
  ~CVRender();

public:
  int CreateWnd(HWND hWnd);
  int DestroyWnd();
  int SetDisplayMode(RenderDisMode_e mode, RenderRect_t *pRect, int img_w,
                     int img_h);
  int Update(unsigned char *pData[3], int size, int width, int height,
             int pitch[3], RenderFormat_e fmt);
  int GetDisplayRect(RenderRect_t *rc);

private:
  HWND wnd_;
  SDL_Window *screen_;
  SDL_Renderer *renderer_;
  SDL_Texture *texture_;
  SDL_Rect rect_wnd_;
  SDL_Rect rect_disp_;
  bool disp_mode_changed_;
  RenderDisMode_e disp_mode_;
  int image_w_;
  int image_h_;

private:
  int GenerateDisplayRect(int width, int height);
  int RebuildRender(int width, int height);
  int CheckWndSize(int w, int h);
};

#endif
